<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/19
 * Time: 2:38
 */

namespace app\controller;


use App;

class BaseController
{
    protected function view($tpl = 'index', $data = [])
    {
        if(strpos($tpl , '/') === false){
           $tpl = strToDirname(get_called_class())."/{$tpl}";
        }
        ob_start();
        App::loadView($tpl , $this , $data);
        $content = ob_get_contents();
        ob_end_clean();
        return $content ;
    }

    protected function putfile($filename , $content)
    {
        $dirname = dirname($filename) ;
        if(!file_exists($dirname)){
            mkdir($dirname , 0777 , true);
        }
        file_put_contents($filename , $content);
    }
}